import { createRouter, createWebHashHistory } from 'vue-router'
import TopCategory from '@/views/category/index'
import SubCategory from '@/views/category/sub'

const Layout = () => import('@/views/Layout')
const Home = () => import('@/views/home')

const Login = () => import('@/views/login/index')
// 路由规则
const routes = [
  // 一级路由布局容器
  { 
    path: '/', 
    component: Layout,
    children: [
      { path: '/', component: Home },
      { path: '/category/:id',component: TopCategory },
      { path: '/category/sub/:id',component: SubCategory },
    ]
  },
  {
    path: '/login',component: Login 
  }
]

// vue2.0 new VueRouter({}) 创建路由实例
// vue3.0 createRouter({}) 
const router = createRouter({
  // 使用hash的路由模式
  history: createWebHashHistory(),
  routes,
  scrollBehavior () {
    return { left:0,top:0 }
  }
})

export default router
